package cn.agiledata.bank.common.service.email;

import java.util.Date;
import java.util.Map;

import cn.agiledata.bank.common.dao.ActionTypeTemplate;
import cn.agiledata.bank.common.service.NotifyMail;
import cn.agiledata.bank.common.util.DateUtil;
import cn.agiledata.bank.common.util.WeatherUtil;
import cn.agiledata.bank.hibernateBean.ScoresHis;
import cn.agiledata.bank.hibernateBean.SubAccount;
import cn.agiledata.bank.hibernateBean.Transaction;
import com.vnv.infrastructure.logic.IPBAppFactory;

public class CancelMail extends NotifyMail {
	private SubAccount email;

	private String mobilemessage = "欢迎使用支付系统";

	public SubAccount getEmail() {
		return email;
	}

	public void setEmail(SubAccount email) {
		this.email = email;
	}

	public String getMobilemessage() {
		return mobilemessage;
	}

	public void setMobilemessage(String mobilemessage) {
		this.mobilemessage = mobilemessage;
	}

	protected SubAccount setMailContext(Map vnvMap, Transaction tran,
			ScoresHis score) {
		setEmailTitle("您的收款申请取消通知");
		String now = DateUtil.date2String(new Date());
		String creditName = WeatherUtil.getNameOrEmailOrMobileByAccount(tran
				.getCredit().getAccount());
		String debitName = WeatherUtil.getNameOrEmailOrMobileByAccount(tran
				.getDebit().getAccount());
		String titlemessage = new String();
		vnvMap.put("credit", WeatherUtil.getNameOrEmailOrMobileByAccount(tran.getCredit().getAccount()));
		vnvMap.put("debit", WeatherUtil.getNameOrEmailOrMobileByAccount(tran.getDebit().getAccount()));
		vnvMap.put("tranId", tran.getTransId());
		vnvMap.put("trantype", "交易");
		vnvMap.put("tranTime", now);
		ActionTypeTemplate at = (ActionTypeTemplate) IPBAppFactory
				.getObj("actionTypeTemplate");
		String status = at.getTransStatusById(tran.getTransStatus())
				.getListName();
		vnvMap.put("transstatue", status);
		vnvMap.put("transtype", "非担保交易");
		vnvMap.put("mobilemessage", getMobilemessage());
		if (tran.getDebit().getId().longValue() == email.getId().longValue()) {
			if (tran.getUpdateUser().equals(
					tran.getDebit().getAccount().getId().toString()))
				titlemessage = "您于" + now + "取消了" + creditName + "向您的收款申请：";
			else
				titlemessage = creditName + "取消了向您的收款申请：";
			vnvMap.put("name", debitName);
			vnvMap.put("titlemessage", titlemessage);
			vnvMap.put("tranId", tran.getTransId());
			vnvMap.put("amount", Math.abs(tran.getAmount().doubleValue()) + "");
			vnvMap.put("fee", Math.abs(tran.getDebitFee().doubleValue()) + "");
			vnvMap.put("trueamount", Math.abs(tran.getAmount().doubleValue())
					+ "");
		} else {
			if (tran.getUpdateUser().equals(
					tran.getDebit().getAccount().getId().toString()))
				titlemessage = debitName + "于" + now + "取消了您的收款申请：";
			else
				titlemessage = "您取消了向" + debitName + "的收款申请：";
			vnvMap.put("titlemessage", titlemessage);
			vnvMap.put("name", creditName);
			vnvMap.put("tranId", tran.getTransId());
			vnvMap.put("amount", Math.abs(tran.getAmount().doubleValue()) + "");
			vnvMap.put("fee", Math.abs(tran.getCreditFee().doubleValue()) + "");
			vnvMap.put("trueamount", Math.abs(tran.getAmount().doubleValue())
					+ "");
		}
		return getEmail();
	}

}
